#pragma once
#include "singleton.h"
#include "MyNtCall.h"
#include "PEhook.h"

//typedef PVOID (WINAPI*MyAddVec)( ULONG First, PVECTORED_EXCEPTION_HANDLER Handler);
//typedef SIZE_T (WINAPI*MyVirQey )(HANDLE hProcess,LPCVOID lpAddress,PMEMORY_BASIC_INFORMATION lpBuffer,SIZE_T dwLength);
//typedef BOOL (WINAPI*MyGetCon)( HANDLE hThread, LPCONTEXT lpContext);
class CAntiWarden:public Singleton<CAntiWarden>
{
    enum
    {
        eAddVec=0,
        eVirQey,
        eGetCon,
        eReadPro,
        eSellHandler,
        eNum
    };
public:
    CAntiWarden(DWORD hh);
    ~CAntiWarden();
    void HookAddVec(HANDLE hThread);
    void FunHook(HANDLE hThread);
    void RemoveAdd();
    void Remove();
protected:
    
    static LONG NTAPI MyVecExepHander(PEXCEPTION_POINTERS ExceptionInfo);

    static SIZE_T WINAPI NtQuery(
        __in      HANDLE hProcess,
        __in_opt  LPCVOID lpAddress,
        __in      DWORD dwZero,
        __out     PMEMORY_BASIC_INFORMATION lpBuffer,
        __in      SIZE_T dwLength,
        __out     DWORD& pSize
        );

    static BOOL WINAPI NtThreadCon(
        __in    HANDLE hThread,
        __inout LPCONTEXT lpContext
        );

    static BOOL WINAPI NtReadPro(
        __in HANDLE hProcess, 
        __in LPCVOID lpBaseAddress,
        __out LPVOID lpBuffer, 
        __in  SIZE_T nSize, 
        __out_opt SIZE_T * lpNumberOfBytesRead);

private:
    CMyNTCall m_Ary[eNum];
    HANDLE    m_Hooks[eNum];
    DWORD     m_hDll;
    DWORD     m_hSize;
    CPEHook   m_oHook;
};